﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using QuizzService.Database;

namespace QuizzService.Service
{
    [ServiceContract]
    public interface IQuizzService
    {
        /// <summary>
        /// Gets all themes
        /// </summary>
        [OperationContract]
        IEnumerable<Theme> GetThemes();

        /// <summary>
        /// Get a specific theme by its id
        /// </summary>
        /// <param name="id">Theme id</param>
        [OperationContract]
        Theme GetTheme(int id);

        /// <summary>
        /// Get all available difficulties
        /// </summary>
        [OperationContract]
        IEnumerable<Difficulty> GetDifficulties();

        /// <summary>
        /// Set the user difficulty
        /// </summary>
        [OperationContract]
        void SetDifficulty(User user, Difficulty difficulty);

        /// <summary>
        /// Get a random quizz
        /// </summary>
        [OperationContract]
        Quizz GetRandomQuizz();

        /// <summary>
        /// Get a random thematic quizz
        /// </summary>
        [OperationContract]
        Quizz GetQuizz(Theme theme);

        /// <summary>
        /// Get a random thematic quizz
        /// </summary>
        [OperationContract]
        Quizz GetQuizzByThemeId(int themeId);

        /// <summary>
        /// Get a specific quizz by its id
        /// </summary>
        [OperationContract]
        Quizz GetSpecificQuizz(int quizzId);
        
        /// <summary>
        /// Save a quizz result
        /// </summary>
        /// <param name="userId">User id</param>
        /// <param name="quizzId">Quizz id</param>
        /// <param name="score">User score</param>
        /// <param name="goodAnswers">Number of good answers</param>
        /// <param name="badAnswers">Number of bad answers</param>
        /// <param name="skipAnswers">Number of skipped answers</param>
        /// <returns></returns>
        [OperationContract]
        int SaveResult(int userId, int quizzId, int score, int goodAnswers, int badAnswers, int skipAnswers);

        /// <summary>
        /// Get a result specified by its id
        /// </summary>
        [OperationContract]
        Result GetResult(int resultId);

        /// <summary>
        /// Get all results of a specific quizz
        /// </summary>
        [OperationContract]
        IEnumerable<Result> GetResults(Quizz q);

        /// <summary>
        /// Get the top ten users of QuizzMe
        /// </summary>
        [OperationContract]
        IEnumerable<User> GetTopTen();

        /// <summary>
        /// Get the rank of a user specified by his id
        /// </summary>
        [OperationContract]
        Rank GetRank(int userId);

        /// <summary>
        /// Get a user by his id
        /// </summary>
        [OperationContract]
        User GetUser(int userId);

        /// <summary>
        /// Get a user by his facebookId and update his name
        /// </summary>
        [OperationContract]
        User GetUserByFbUid(string fbUid, string name);
    }

    [DataContract]
    public class Rank
    {
        [DataMember]
        public int Position { get; set; }

        [DataMember]
        public int Total { get; set; }

        public override string ToString()
        {
            return string.Format("{0}/{1}", Position, Total);
        }
    }
}
